<?php

namespace App\Containers\AppSection\Project\UI\API\Transformers;

use App\Containers\AppSection\Project\Models\Condition;
use App\Containers\AppSection\Type\UI\API\Transformers\TypeTransformer;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Item;

class ConditionTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'type',
        'repayment',
        'output',
    ];

    /**
     * @var  array
     */
    protected array $availableIncludes = [
        'rating'
    ];

    public function transform(Condition $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'type_key' => $t->type_key,
            'own_version' => $t->own_version,
            'min' => $t->min,
            'target' => $t->target,
            'percent' => $t->percent,
            'loan' => $t->loan,
            'period' => $t->period,
            'repayment_key' => $t->repayment_key,
            'deffer_period' => $t->deffer_period,
            'penalty_per_day' => $t->penalty_per_day,
            'charge_penalty_first_day' => $t->charge_penalty_first_day,
            'percents_calculation' => $t->percents_calculation,
            'output_key' => $t->output_key,
        ];
    }

    public function includeType(Condition $t): ?Item
    {
        return $this->nullableItem($t->type, new TypeTransformer);
    }

    public function includeRating(Condition $t): Item
    {
        return $this->item($t->rating, new TypeTransformer);
    }

    public function includeRepayment(Condition $t): Item
    {
        return $this->item($t->repayment, new TypeTransformer);
    }

    public function includeOutput(Condition $t): Item
    {
        return $this->item($t->output, new TypeTransformer);
    }
}
